#include <iostream>
#include <cstring>
using namespace std;

const int N = 110;

int T;
int r, c;
int a[N][N];
int f[N][N];

int main()
{
    freopen("cin.txt", "r", stdin);
    cin >> T;
    while (T--)
    {
        cin >> r >> c;
        for (int i = 1; i <= r; ++i)
            for (int j = 1; j <= c; ++j)
                cin >> a[i][j];
        for (int i = 1; i <= r; ++i)
            for (int j = 1; j <= c; ++j)
                f[i][j] = max(f[i - 1][j] + a[i][j], f[i][j - 1] + a[i][j]);
        cout << f[r][c] << endl;
    }
    return 0;
}